Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] OWPredictions: Allow classification when data has no target column #2183

Merged
merged 1 commit into from
Apr 6, 2017

Conversation

janezd
Copy link
Contributor

@janezd janezd commented Mar 31, 2017

Issue

OWPredictions reported mismatching targets if the data had not target column (#2148).

This occurred because the data's class_var was None, and it was thus not the same as the target of predictors.

Description of changes

The widget's self.class_var is now set from the target of the models. All models must have the same target. Also, if the data has a target, it has to be the same as the models' target.

This required several other changes in the widget to cope with situations that could not occur previously.

Includes
  • Code changes
  • Tests

@janezd janezd changed the title OWPredictions: Allow classification when data has no target column [FIX] OWPredictions: Allow classification when data has no target column Apr 2, 2017
@jerneju jerneju requested review from jerneju and removed request for jerneju April 6, 2017 06:45
@ajdapretnar
Copy link
Contributor

@lanzagar Could you please just check the code as well and merge. I only tested it on cases and it works.


def _update_predictions_model(self):
"""Update the prediction view model."""
if self.data is not None:
if self.data is not None and self.class_var is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the second part (class_var not None) also imply the first (data not None).

(The same if appears in a couple of places)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.class_var comes from predictors and can be not None even if no data is present. See https://github.com/janezd/orange3/blob/21ba4679bf19efde4498363a56c69bf3798ea0f9/Orange/widgets/evaluate/owpredictions.py#L224.

newmetas, newcolumns = self._classification_output_columns()
else:
newmetas, newcolumns = self._regression_output_columns()

attrs = list(self.data.domain.attributes) if self.output_attrs else []
metas = list(self.data.domain.metas) + newmetas
domain = Orange.data.Domain(attrs, class_var, metas=metas)
domain = \
Orange.data.Domain(attrs, self.data.domain.class_var, metas=metas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we assure at the beginning that self.data.domain.class_var must be equal to self.class_var, then the second (shorter/direct) version would look nicer here. And the line break would probably not be necessary :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I recalled: I did have self.class_var and it fit into a single line. But this fails exactly in the case that this PR is fixing: if self.data.domain.class_var is None, the output data should have no class, either. Changing this to self.class_var can add a column of unknown values if the original data has no class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants